package xyz.fuqufyb.aec.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xyz.fuqufyb.aec.dao.CustomerMapper;
import xyz.fuqufyb.aec.data.TableResult;
import xyz.fuqufyb.aec.entity.Customer;
import xyz.fuqufyb.aec.service.ICustomerService;

import java.util.List;
import java.util.Map;

/**
 * @author 用户: fyb
 * @description class: CustomerServiceImpl
 * @date 时间: 2021/2/1 22:00
 */
@Service("ICustomerService")
public class CustomerServiceImpl implements ICustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public TableResult getPageCustomer(Map<String,Object> maps) {

        String page = (String) maps.get("page");
        String limit = (String) maps.get("limit");

        if (page!= null && limit != null) {
            PageHelper.startPage(Integer.parseInt(page), Integer.parseInt(limit));
            List<Customer> pageCustomer = customerMapper.getPageCustomer(maps);

            PageInfo pageInfo = new PageInfo(pageCustomer);

            return TableResult.getTableResultSuccess(pageInfo.getTotal(),pageInfo.getList());
        }
        return TableResult.getTableResultError("参数不能为空");
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        int i = customerMapper.deleteByPrimaryKey(id);
        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public int insert(Customer record) {

        int insert = customerMapper.insert(record);

        if (insert > 0) {
            return insert;
        }
        return 0;
    }

    @Override
    public int insertSelective(Customer record) {

        int i = customerMapper.insertSelective(record);

        if (i > 0) {

            return i;
        }
        return 0;
    }

    @Override
    public Customer selectByPrimaryKey(Integer id) {

        Customer customer = customerMapper.selectByPrimaryKey(id);


        if (customer != null) {
            return customer;
        }
        return null;
    }

    @Override
    public int updateByPrimaryKeySelective(Customer record) {

        int i = customerMapper.updateByPrimaryKeySelective(record);

        if (i > 0) {

            return i;
        }
        return 0;
    }

    @Override
    public int updateByPrimaryKeyWithBLOBs(Customer record) {

        int i = customerMapper.updateByPrimaryKeyWithBLOBs(record);

        if (i > 0) {

            return i;
        }
        return 0;
    }

    @Override
    public int updateByPrimaryKey(Customer record) {

        int i = customerMapper.updateByPrimaryKey(record);

        if (i > 0) {
            return i;
        }
        return 0;
    }

    @Override
    public int deleteByCustomerIds(List<Integer> asList) {

        int i = customerMapper.deleteByCustomerIds(asList);

        if (i>0){

         return i;
        }
        return 0;
    }

    @Override
    public List<Customer> getListCustomer() {
        List<Customer> customers =  customerMapper.getListCustomer();
        if (customers.isEmpty()) {
            return null;
        }
        return customers;
    }
}
